<?php

function menuItem($id='',$label='',$href='',$pars=array()){
	$p        = array('id'=>$id,'label'=>$label,'href'=>$href);
    $default  = array('class'=>'','title'=>'');
    if(!is_array($pars)){
      $pars = array($pars);
    }
    $ret      = array_merge($default,$pars,$p);
    return($ret);}

function smarty_Select(&$smarty,$sql,$assign,$indexBy='',$spy=false){

    $db = getDb();

	if(!$smarty)
		return 0;

	if($indexBy==''){
		$rows=$db->SelectAll($sql);
	}
	else{
		$rows=$db->SelectAllBy($sql,$indexBy);
	}
	
	$smarty->assign($assign,$rows);
	
	return $db->Count;
}



function smarty_SelectOne(&$smarty,$sql,$assign,$indexBy='',$spy=false){
	
  $db = getDb();

	if($spy)
		echo $sql;

	if(!$smarty)
		return 0;

	if($indexBy==''){
		$rows=$db->SelectAll($sql);
		if($db->Count==1)
			$rows=$rows[0];
	}
	else{
		$rows=$db->SelectAllBy($sql,$indexBy);
		if($db->Count==1)
			$rows=$rows[0];
	}
	
	$smarty->assign($assign,$rows);
	
	return $db->Count;
}

function smarty_SelectFirst(&$smarty,$sql,$assign,$indexBy='',$spy=false){
	return smarty_SelectOne($smarty,$this,$sql,$assign,$indexBy,$spy);

}
?>
